BINARY    := {{ cookiecutter.binary_name }}
GO_DIR    := src/go/{{ cookiecutter.binary_name }}
BUILD_DIR := $(GO_DIR)/build

GO        := go
GOFLAGS   :=

VERSION   := $(shell cat meta-data/VERSION 2>/dev/null || echo "dev")
LDFLAGS   := -ldflags "-X main.version=$(VERSION)"

.PHONY: all build test test-verbose vet tidy clean run help

all: build

## build: compile the binary to $(BUILD_DIR)/$(BINARY)
build:
	@mkdir -p $(BUILD_DIR)
	cd $(GO_DIR) && $(GO) build $(GOFLAGS) $(LDFLAGS) -o build/$(BINARY) .

## test: run all Go tests
test:
	cd $(GO_DIR) && $(GO) test $(GOFLAGS) ./...

## test-verbose: run all Go tests with verbose output
test-verbose:
	cd $(GO_DIR) && $(GO) test $(GOFLAGS) -v ./...

## vet: run go vet
vet:
	cd $(GO_DIR) && $(GO) vet ./...

## tidy: tidy and verify go modules (run this once before the first build)
tidy:
	cd $(GO_DIR) && $(GO) mod tidy && $(GO) mod verify

## clean: remove build artifacts
clean:
	rm -rf $(BUILD_DIR)

## run: build and print help (quick smoke test)
run: build
	$(BUILD_DIR)/$(BINARY) --help

## help: show this help
help:
	@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/^## /  /'
